package item.inkcloud.communityservice.service;


import item.inkcloud.communityservice.entity.Comment;
import item.inkcloud.communityservice.feignClient.UserServiceFeignClient;
import item.inkcloud.communityservice.mapper.CommentMapper;
import item.inkcloud.communityservice.pojo.ArticleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentService {

    @Autowired
    UserServiceFeignClient userServiceFeignClient;

    @Autowired
    CommentMapper commentMapper ;


    public int publishComment(Comment comment,String userid){

        String username = userServiceFeignClient.getUsernameById(userid);

        comment.setUsername(username);

        String currentTime = ArticleUtils.getCurrentDate();

        comment.setCommentTime(currentTime);

        try {

            commentMapper.publishComment(comment);

            return 1;

        }catch (Exception e){

            return 0;
        }

    }


}
